<script>
export default {
  render(clearElement) {
    let { sticky, fixed, back, title } = this.$props;
    let backElemen = null;
    if (back) {
      let backIconClass = "icon-jiantou_xiangzuo";

      backElemen = clearElement(
        "div",
        { class: "back-button", on: { click: this.clickBack.bind(this) } },
        [
          clearElement("i", {
            class: ["overall-icon", backIconClass, "back-icon"],
          }),
          clearElement("span", { class: "back-button-span" }, "返回"),
        ]
      );
    }
    return clearElement(
      "div",
      {
        class: {
          "overall-flex overall-align-center header": true,
          "header-sticky": sticky,
          "header-fixed": fixed,
        },
      },
      [backElemen, clearElement("span", { class: "title" }, title)]
    );
  },

  props: {
    title: {
      type: String,
      default: "页面标题",
    },
    padding: {
      type: String,
      default: "15px 20px",
    },
    background: {
      type: String,
      default: "white",
    },
    back: {
      type: Boolean,
      default: false,
    },
    sticky: {
      type: Boolean,
      default: true,
    },
    fixed: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    clickBack() {
      this.$router.back();
    },
  },
};
</script>

<style lang="scss" scoped>
.header {
  padding: 17px 24px;
  background: white;
  margin-bottom: 10px;
  width: 100%;
}
.title {
  font-size: 1.2rem;
}

.header-content {
  margin-top: 10px;
}
.header-content:empty {
  margin-top: 0px;
}
.back-button {
  width: 80px;
  height: 30px;
  border-radius: 30px;
  display: flex;
  border: 1px solid #c3c3c344;
  transition: 180ms all linear;
  box-sizing: border-box;
  padding: 4px 20px;
  margin-right: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-button:hover {
  width: 110px;
  border-color: rgb(126, 129, 129);
}
.back-button:hover .back-icon {
  display: inline-block;
}
.back-button-span {
  font-size: 0.8rem;
  flex: 1;
  text-align: center;
  min-width: 50px;
}
.header-sticky {
  position: sticky;
  top: 0px;
  left: 0px;
  z-index: $pageHeaderStickyIndex;
}
.header-fixed {
  position: fixed;
  top: 0px;
  left: 0px;
}
.back-icon {
  display: none;
  transition: 300ms all linear;
  font-size: 1rem;
  color: rgb(126, 129, 129);
  animation: back-icon 1122ms linear 70ms infinite alternate;
}
@keyframes back-icon {
  0% {
    transform: translateX(0px);
  }
  50% {
    transform: translateX(-5px);
  }
  100% {
    transform: translateX(5px);
  }
}
</style>
